package com.itheima.server.controller;

import com.itheima.server.service.UserService;
import com.tanhua.model.domain.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/user")
public class LoginController {

    @Autowired
    private UserService userService;

    /**
     *接口名称：登录---获取验证码
     *接口路径：POST/user/login
     */
    @PostMapping("/login")
    public ResponseEntity login(@RequestBody Map<String,String> paramMap){
        //1.获取手机号
        String phone = paramMap.get("phone");
        //2.把手机号交给service去发送短信
        userService.sendMsg(phone);
        return ResponseEntity.ok(null);
    }


    /**
     *接口名称：登录---验证码校验
     *接口路径：POST /user/loginVerification
     */
    @PostMapping("/loginVerification")
    public ResponseEntity loginVerification(@RequestBody Map<String,String> paramMap){
        //1.  获取手机号和验证码
        String phone = paramMap.get("phone");
        String verificationCode = paramMap.get("verificationCode");
        //2. 把手机号和验证码交给service去发送短信
        Map<String,Object> map = userService.verificationCode(phone,verificationCode);
        return ResponseEntity.ok(map);
    }

}
